package com.mq.rabbitmqtrac.service.impl;

import com.mq.rabbitmqtrac.domain.Blog;
import com.mq.rabbitmqtrac.repository.BlogRepository;
import com.mq.rabbitmqtrac.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BlogServiceImpl implements BlogService {

    @Autowired
    private BlogRepository blogRepository;


    @Override
    public Blog saveBlog(@RequestBody Blog blog) throws Exception {
        return blogRepository.save(blog);
    }

    @Override
    public Blog getBlog(@PathVariable("id") long id) throws Exception {
        return blogRepository.findById(id).isPresent() ? blogRepository.findById(id).get() : null;

    }
}
